package com.cjack.frenchexcel.request.mooncard;

/**
 * 访问mooncard的token信息
 */
public class TokenInfo {
    //token的失效的误差，目前暂定为1分钟，也就是在距离token真正过期1分钟的时候，就需要刷新token
    private static final Long MISS_ERROR = 60 * 1000l;


    //{"access_token":"op0yR3Jex1ROoD3VjsxvlgkBCRoRxJ4MLP4uDt0qesw","token_type":"Bearer","expires_in":7200,"refresh_token":"AXJK7MF2tFiPXl5B8aLWLpRC1eL_5A6F3lzfPUkr3Ik","scope":"public","created_at":1574766323}
    private String access_token;
    private String token_type;
    private Long expires_in;
    private String refresh_token;
    private String scope;
    private Long created_at;

    public String getAccess_token() {
        return access_token;
    }

    public void setAccess_token(String access_token) {
        this.access_token = access_token;
    }

    public void setToken_type(String token_type) {
        this.token_type = token_type;
    }

    public void setExpires_in(Long expires_in) {
        this.expires_in = expires_in;
    }

    public void setRefresh_token(String refresh_token) {
        this.refresh_token = refresh_token;
    }

    public void setScope(String scope) {
        this.scope = scope;
    }
    public void setCreated_at(Long created_at) {
        this.created_at = created_at;
    }

    /**
     * 检查token是否过期
     * @return true代表以及过期，false代表未过期
     */
    public boolean expire(){
        if( System.currentTimeMillis() - created_at > (expires_in - MISS_ERROR)){
            return true;
        }else{
            return false;
        }
    }
}
